<!DOCTYPE html>
<html>
<head>
	<title>react-form2</title>
    <meta charset="UTF-8" />
	<script src='../node_modules/react/umd/react.development.js'></script>
	<script src='../node_modules/react-dom/umd/react-dom.development.js'></script>
    <script src='../node_modules/babel-standalone/babel.min.js'></script>
    
</head>
<body>
    <div id="my"></div>
    <script type="text/babel">
    class Hello extends React.Component{
        constructor(){
            super();
            this.state = {
                name:'',
                male:true,
                select:'c'
            };
        };
        handleChange(e){
            var name = e.target.name;
            this.setState({
                [name]:e.target.value 
            })
        };
        handleRadio(e){
            var male = e.target.value =='man'?true:false;
            var male2;
            this.setState({
                male:male,
               // male2:e.target.value
            })
        };
        submit() {
            alert(JSON.stringify(this.state))
        }
        
        render(){ 
            return (
                <div>
                    <p>
                        <label>姓名：</label>
                        <input type="text"
                          name='name'
                          value={this.state.name} 
                          onChange={(e)=>this.handleChange(e)}/>
                    </p>
                     <p>
                         <label>性别：</label>
                            <input type="radio" 
                                name="radioName" 
                                checked={this.state.male} 
                                onChange={(e)=>this.handleRadio(e)}
                                value='man'/>  男
                            <input type="radio" 
                                name="radioName" 
                                checked={!this.state.male}
                                onChange={(e)=>this.handleRadio(e)}
                                value='woman'/>  女
                     </p>
                     <input type="checkbox" name="checkbox" defaultChecked/>123
                     <div>
                         <select name="select" value={this.state.select} onChange={(e)=>this.handleChange(e)}>
                             <option value='a'>a</option>
                             <option value='b'>b</option>
                             <option value='c'>c</option>
                         </select>
                     </div>
                    <p>
                        <button onClick={()=>this.submit()}>提交</button>
                    </p>
                </div>
                )
        }
    };
    
     ReactDOM.render(
          <Hello/>,
        document.getElementById('my')
    )
    </script>
</body>
</html>